﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Proggy.Web.Cms.ContentModel
{
    /// <summary>
    /// The front end view model attribute
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class ContentModelAttribute : Attribute
    {
       /// <summary>
       /// Constructor
       /// </summary>
       /// <param name="friendlyName"></param>
       /// <param name="pathToIcon"></param>
       /// <param name="canBeRootNode"></param>
       /// <param name="ignoreBaseClass"></param>
       /// <param name="allowedChildViewModelTypeAliases"></param>
       /// <param name="allowedTemplates"></param>
       /// <param name="controllerNameSpace"></param>
        public ContentModelAttribute(string friendlyName, string pathToIcon, bool canBeRootNode, bool ignoreBaseClass, string allowedChildViewModelTypeAliases, string allowedTemplates, string controllerNameSpace)
        {
            // set friendly name
            this.FriendlyName = friendlyName;
            this.IgnoreBaseClass = ignoreBaseClass;

            //// set allowed vms
            //this.AllowedChildViewModelTypeAliases =
            //    !string.IsNullOrEmpty(allowedChildViewModelTypeAliases) ? 
            //        allowedChildViewModelTypeAliases.Split(',') : new string[] { };

            // check
            if (allowedChildViewModelTypeAliases == null) {
                this.AllowedChildViewModelTypeAliases = null;
            }
            else if (allowedChildViewModelTypeAliases == string.Empty)
            {
                this.AllowedChildViewModelTypeAliases = new string[] { };
            }
            else {
                this.AllowedChildViewModelTypeAliases = allowedChildViewModelTypeAliases.Split(',');
            }

            // set allowed templates
            this.AllowedTemplates =
                !string.IsNullOrEmpty(allowedTemplates) ?
                    allowedTemplates.Split(',') : new string[] { };

            // set controller namespace
            this.ControllerNamespace = controllerNameSpace;

            // set can be root
            this.CanBeRootNode = canBeRootNode;

            // set icon path
            this.PathToIcon = pathToIcon;
        }

        /// <summary>
        /// Path to icon (eg "~/Content/Images/MyIcon.png")
        /// </summary>
        public string PathToIcon { get; private set; }

        /// <summary>
        /// The friendly name for this view model
        /// </summary>
        public string FriendlyName { get; private set; }

        /// <summary>
        /// String array of allowed view model type aliases
        /// </summary>
        public string[] AllowedChildViewModelTypeAliases { get; private set; }

        /// <summary>
        /// String array of allowed templates
        /// </summary>
        public string[] AllowedTemplates { get; private set; }

        /// <summary>
        /// The namespace of the corresponding controller (eg if this was called "MyViewModel" and 
        /// the ns was "MyViewModels.Controllers" the controller would be "MyViewModels.Controllers.MyViewModelController")
        /// </summary>
        public string ControllerNamespace { get; private set; }

        /// <summary>
        /// If true, can be root node
        /// </summary>
        public bool CanBeRootNode { get; private set; }

        /// <summary>
        /// If true, base class will not be available to the end user
        /// </summary>
        public bool IgnoreBaseClass { get; set; }
    }
}
